home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / exportSkinMap.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.3 KB  |  266 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Procedure: exportSkinMap
  19. //
  20. //    Description:
  21. //        This mel script is used to export a weight map for the skinning
  22. //        data for each joint that affects the selected skin.
  23. //
  24. //        To use, select the skin or skins, and type "exportSkinMap"
  25. //
  26. //
  27. proc int checkForLattice(string $obj) {
  28.     
  29.     string $cpShape[] = `ls -type controlPoint $obj`;
  30.     int $isLattice = 0;
  31.     if (size($cpShape) > 0) {
  32.         if (nodeType($obj) == "lattice") {
  33.             $isLattice = 1;
  34.         }
  35.     } else {
  36.         $cpShape = `listRelatives -pa -type controlPoint $obj`;
  37.         for ($cp in $cpShape) {
  38.             if (nodeType($cp) == "lattice") {
  39.                 $isLattice = 1;
  40.                 break;
  41.             }
  42.         }
  43.     }
  44.     if ($isLattice) {
  45.         string $warnMsg = ("Skipping "+$obj+": Lattice maps are not supported by Artisan.");
  46.         warning($warnMsg);
  47.     }
  48.     return $isLattice;
  49. }
  50.  
  51. proc string convertToFileName(string $skin, string $inf)
  52. {
  53.     string $infNameForFile;
  54.     string $skinNameForFile;
  55.     string $ibuff[];
  56.     int $numTokens = tokenize($inf,"|",$ibuff);
  57.     for ($ii = 0; $ii < $numTokens; $ii++) {
  58.         $infNameForFile += $ibuff[$ii];
  59.         if ($ii != $numTokens-1) {
  60.             $infNameForFile += "_";
  61.         }
  62.     }
  63.     clear($ibuff);
  64.     int $numTokens = tokenize($skin,"|",$ibuff);
  65.     for ($ii = 0; $ii < $numTokens; $ii++) {
  66.         $skinNameForFile += $ibuff[$ii];
  67.         if ($ii != $numTokens-1) {
  68.             $skinNameForFile += "_";
  69.         }
  70.     }
  71.     return ($infNameForFile+"_"+$skinNameForFile);
  72. }
  73.  
  74. global proc int exportSkinWeightMap(string $fileName, string $fileType)
  75. {
  76.     source "artAttrSkinCallback.mel";
  77.     source "artAttrSkinJointMenu.mel";
  78.  
  79.     // Make sure we are in Skin Paint Weight Tool.
  80.     string $currCtx = `currentCtx`;
  81.     artAttrSkinToolScript 4;
  82.  
  83.     string $artCmd = "artAttrCtx -query -exportfiletype `currentCtx`";
  84.     $fileType = eval( $artCmd );
  85.  
  86.     $fileType = tolower($fileType);
  87.     if ($fileType == "IFF") {
  88.         $fileType = "iff";
  89.     } else if ($fileType == "JPEG") {
  90.         $fileType = "jpg";
  91.     } else if ($fileType == "TIFF") {
  92.         $fileType = "tif";
  93.     } else if ($fileType == "Quantel") {
  94.         $fileType = "qtl";
  95.     } else if ($fileType == "Alias") {
  96.         $fileType = "pix";
  97.     } else if ($fileType == "SoftImage") {
  98.         $fileType = "pic";
  99.     } else if ($fileType == "GIF") {
  100.         $fileType = "gif";
  101.     } else if ($fileType == "RLA") {
  102.         $fileType = "rla";
  103.     } else if ($fileType == "SGI") {
  104.         $fileType = "sgi";
  105.     } else if ($fileType == "EPS") {
  106.         $fileType = "eps";
  107.     }else if  ($fileType == "Targa") {
  108.         $fileType = "tga";
  109.     }else if  ($fileType == "WindowsBitmap") {
  110.         $fileType = "bmp";
  111.     }else if  ($fileType == "QuickTime Image") {
  112.         $fileType = "qtif";
  113.     }else if  ($fileType == "QuickDraw") {
  114.         $fileType = "qd";
  115.     }else if  ($fileType == "Photoshop") {
  116.         $fileType = "psd";
  117.     }else if  ($fileType == "PNG") {
  118.         $fileType = "png";
  119.     }else if  ($fileType == "MacPaint") {
  120.         $fileType = "pntg";
  121.     }
  122.  
  123.     // Get the selected skins.
  124.     int $skinCount = 0;
  125.     string $currentSelection[] = `ls -sl`;
  126.     string $skins[];
  127.     string $clusters[];
  128.     int $latticeFound = 0;
  129.     for ($sel in $currentSelection) {
  130.         if (checkForLattice($sel)) {
  131.             $latticeFound = 1;
  132.             continue;
  133.         }
  134.         
  135.         // Find the cluster.
  136.         string $buff[];
  137.         tokenize($sel,".",$buff);
  138.         string $cluster = findRelatedSkinCluster($buff[0]);
  139.         if ("" != $cluster) {
  140.             $skins[$skinCount] = $sel;
  141.             $clusters[$skinCount] = $cluster;
  142.             $skinCount++;
  143.         }
  144.     }
  145.  
  146.     if (0 == $skinCount) {
  147.         if ($latticeFound) {
  148.             error("Lattice maps are not supported by Artisan.");
  149.         } else {            
  150.             error("No skins were selected.");
  151.         }
  152.         return 0;
  153.     }
  154.  
  155.     // Find the file and directory name.
  156.     string $buff[];
  157.     tokenize($fileName,"/",$buff);
  158.     string $fn = $buff[size($buff)-1];
  159.     tokenize($fn,"\\",$buff);
  160.     $fn = $buff[size($buff)-1];    
  161.     $dir = substring($fileName,1,size($fileName)-size($fn));
  162.     tokenize($fn,".",$buff);
  163.     $fn = $buff[0];
  164.  
  165.     $fileName = ($dir+$fn+".weightMap");
  166.     $fileId = fopen( $fileName, "w" );
  167.     if ($fileId == 0) {
  168.         error("Unable to open the file: " + $fileName);
  169.         return 0;
  170.     }
  171.  
  172.     int $passed = 1;
  173.  
  174.     // Write out a master file that links the joint names to the map names.
  175.     fprint($fileId,"// Exported skin weight map file\n");
  176.     fprint($fileId,"// \n");
  177.     $skinCount = 0;
  178.     int $mapCount = 0;
  179.     for ($skin in $skins) {
  180.         string $infs[] = `skinCluster -q -wi $clusters[$skinCount]`;
  181.         for ($inf in $infs) {
  182.             string $dat = ($skin+"\t"+$inf+"\t");
  183.             string $infName = convertToFileName($skin,$inf);
  184.             string $mapFn = ($fn+"_"+$infName+"."+$fileType);
  185.             $dat += ($mapFn+"\n");
  186.             fprint($fileId,$dat);
  187.             $mapCount++;
  188.         }
  189.         $skinCount++;
  190.     }
  191.  
  192.     if (catch(`fclose $fileId`)) {
  193.         error("Unable to close the file: " + $fileName);
  194.         $passed = 0;
  195.     }
  196.  
  197.     if ($mapCount > 5) {
  198.         string $confirm = `confirmDialog -m ($mapCount+" skin maps will be written to disk. Proceed?") -b "Yes" -b "No" -db "Yes"`;
  199.         if ($confirm != "Yes") {
  200.             sysFile -del $fileName;
  201.             return 0;
  202.         }
  203.     }
  204.  
  205.     // Make a directory to contain the maps.
  206.     string $mapDir = ($dir + $fn);
  207.     if (! `file -q -exists $mapDir` ) {
  208.         workspace -cr $mapDir;
  209.     }
  210.     
  211.     // Export the maps for each joint.
  212.     if ($passed) {
  213.         $skinCount = 0;    
  214.         for ($skin in $skins) {
  215.             string $infs[] = `skinCluster -q -wi $clusters[$skinCount]`;
  216.             for ($inf in $infs) {
  217.                 // Generate a map name for this influence.
  218.                 string $infName = convertToFileName($skin,$inf);
  219.                 string $mapFn = ($mapDir+"/"+$fn+"_"+$infName+"."+$fileType);
  220.                 if (`file -q -exists $mapFn`) {
  221.                     sysFile -del $mapFn;
  222.                 }
  223.  
  224.                 // Set the influence into the tool.
  225.                 string $shortName = artAttrSkinShortName($inf);
  226.                 select -r $skin;
  227.                 artSkinSelectInfluence( "artAttrCtx", $inf, $shortName );
  228.                 
  229.                 // Make sure that the file name  will not be expanded.
  230.                 artAttrCtx -e -expandfilename false `currentCtx`;
  231.  
  232.                 // Export the map for that influence now.
  233.                 artAttrCtx -e -exportfilesave $mapFn `currentCtx`;
  234.             }
  235.             $skinCount++;
  236.         }
  237.     }
  238.     
  239.     // Go back to the original context.
  240.     setToolTo $currCtx;
  241.     select -r $currentSelection;
  242.     
  243.     return $passed;
  244. }
  245.  
  246. global proc exportSkinMap( string $version, string $args[] ) {
  247.  
  248.     if (`about -evalVersion`) {
  249.         confirmDialog
  250.             -m "Exporting of skin maps is not supported in Maya PLE."
  251.             -b "Cancel" -db "Cancel";
  252.         return;
  253.     }
  254.  
  255.     // set the fileBrowser directory to the images dir if it exists
  256.     //
  257.     string $imageDir = (`workspace -q -rd`+"sourceimages\/");
  258.     if (`file -q -ex $imageDir`) {
  259.         workspace -dir $imageDir;
  260.     }
  261.  
  262.     // bring up the file browser dialog so that they can choose a file name
  263.     //
  264.     fileBrowser( "exportSkinWeightMap", "Write Map", "map", 1);
  265. }
  266.